package com.qyer.search.report;

import com.qyer.log.ContentShowLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * User: Z J Wu Date: 2016/01/07 Time: 20:24 Package: com.qyer.search.report
 */
public class Reporter implements Runnable {

  private static final Logger LOGGER = LoggerFactory.getLogger(Reporter.class);

  @Override public void run() {
    SearchReportItem sri;
    ReporterQueue reporterQueue = ReporterQueue.getInstance();
    try {
      while (true) {
        sri = reporterQueue.takeFromQueue();
        if (sri == null) {
          continue;
        }
        if (sri.isPill()) {
          break;
        }
        try {
          ContentShowLogger.logSearchResult(sri);
        } catch (Exception e) {
          LOGGER.warn("Cannot send report({})", e);
        }
      }
    } catch (InterruptedException e) {
      LOGGER.warn("Reporter is interrupted", e);
    }
    LOGGER.info("Reporter is stopped.");
  }
}
